﻿Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class ConnectorEditor
        ' Methods
        Public Sub New(ByVal connectorEdited As Connector)
            Me.editedConnector = connectorEdited
            Me.serviceProvider = Me.editedConnector.Source.AssociatedDesigner.Activity.Site
            Me.CreateEditPoints
        End Sub

        Private Sub AddEditPoints(ByVal editPointType As EditPointTypes)
            If (editPointType = EditPointTypes.ConnectionEditPoint) Then
                If ((Me.editPoints.Count = 0) OrElse Not Me.editPoints.Item(0).EditedConnectionPoint.Equals(Me.Source)) Then
                    Me.editPoints.Insert(0, New EditPoint(Me, Me.Source))
                End If
                If ((Me.editPoints.Count < 2) OrElse Not Me.editPoints.Item((Me.editPoints.Count - 1)).EditedConnectionPoint.Equals(Me.Target)) Then
                    Me.editPoints.Add(New EditPoint(Me, Me.Target))
                End If
            ElseIf (editPointType = EditPointTypes.MidSegmentEditPoint) Then
                Dim num As Integer = (Me.Source.Bounds.Width * 4)
                Dim i As Integer
                For i = 0 To (Me.editPoints.Count - 1) - 1
                    If ((Me.editPoints.Item(i).Type <> EditPointTypes.MidSegmentEditPoint) AndAlso (Me.editPoints.Item((i + 1)).Type <> EditPointTypes.MidSegmentEditPoint)) Then
                        Dim segments As Point() = New Point() { Me.editPoints.Item(i).Location, Me.editPoints.Item((i + 1)).Location }
                        If (DesignerGeometryHelper.DistanceOfLineSegments(segments) > num) Then
                            Dim point As Point = DesignerGeometryHelper.MidPointOfLineSegment(Me.editPoints.Item(i).Location, Me.editPoints.Item((i + 1)).Location)
                            Me.editPoints.Insert((i + 1), New EditPoint(Me, EditPointTypes.MidSegmentEditPoint, point))
                        End If
                    End If
                Next i
            ElseIf ((editPointType = EditPointTypes.MultiSegmentEditPoint) AndAlso (Me.editPoints.Count = 2)) Then
                Dim list As New List([Of] Point)(Me.editedConnector.ConnectorSegments)
                If ((list.Count > 0) AndAlso (list.Item(0) Is Me.Source.Location)) Then
                    list.RemoveAt(0)
                End If
                If ((list.Count > 0) AndAlso (list.Item((list.Count - 1)) Is Me.Target.Location)) Then
                    list.RemoveAt((list.Count - 1))
                End If
                Dim list2 As New List([Of] EditPoint)
                Dim j As Integer
                For j = 0 To list.Count - 1
                    list2.Add(New EditPoint(Me, EditPointTypes.MultiSegmentEditPoint, list.Item(j)))
                Next j
                Me.editPoints.InsertRange((Me.editPoints.Count - 1), list2.ToArray)
            End If
        End Sub

        Private Sub CreateEditPoints()
            Me.editPoints.Clear
            Me.AddEditPoints(EditPointTypes.ConnectionEditPoint)
            Me.AddEditPoints(EditPointTypes.MultiSegmentEditPoint)
            Me.AddEditPoints(EditPointTypes.MidSegmentEditPoint)
            Me.ValidateEditPoints
        End Sub

        Public Function GetCursor(ByVal cursorPoint As Point) As Cursor
            Dim cursor As Cursor = Cursors.Default
            If (Not Me.activeEditPoint Is Nothing) Then
                Return ConnectionManager.NewConnectorCursor
            End If
            Dim point As EditPoint
            For Each point In Me.editPoints
                If point.Bounds.Contains(cursorPoint) Then
                    Return ConnectionManager.SnappedConnectionCursor
                End If
            Next
            Return cursor
        End Function

        Private Function GetPointsFromEditPoints(ByVal editPoints As List([Of] EditPoint)) As List([Of] Point)
            Dim list As New List([Of] Point)
            Dim i As Integer
            For i = 0 To editPoints.Count - 1
                Dim point As EditPoint = editPoints.Item(i)
                If ((point.Type = EditPointTypes.ConnectionEditPoint) OrElse (point.Type = EditPointTypes.MultiSegmentEditPoint)) Then
                    list.Add(point.Location)
                End If
            Next i
            Return list
        End Function

        Private Function GetService(ByVal serviceType As Type) As Object
            Dim service As Object = Nothing
            If (Not Me.serviceProvider Is Nothing) Then
                service = Me.serviceProvider.GetService(serviceType)
            End If
            Return service
        End Function

        Public Function HitTest(ByVal point As Point) As Boolean
            Dim i As Integer
            For i = 0 To Me.editPoints.Count - 1
                Dim point2 As EditPoint = Me.editPoints.Item(i)
                If point2.Bounds.Contains(point) Then
                    Return True
                End If
            Next i
            Return False
        End Function

        Private Sub Invalidate()
            Dim service As WorkflowView = [TryCast](Me.GetService(GetType(WorkflowView)),WorkflowView)
            If (Not service Is Nothing) Then
                Dim logicalRectangle As Rectangle = DesignerGeometryHelper.RectangleFromLineSegments(Me.GetPointsFromEditPoints(Me.editPoints).ToArray)
                logicalRectangle.Inflate(1, 1)
                service.InvalidateLogicalRectangle(logicalRectangle)
            End If
        End Sub

        Public Function OnBeginEditing(ByVal point As Point) As Boolean
            Me.CreateEditPoints
            Dim point2 As EditPoint = Nothing
            Dim i As Integer = (Me.editPoints.Count - 1)
            Do While (i >= 0)
                If Me.editPoints.Item(i).Bounds.Contains(point) Then
                    point2 = Me.editPoints.Item(i)
                    Exit Do
                End If
                i -= 1
            Loop
            If ((Not point2 Is Nothing) AndAlso ((point2.EditedConnectionPoint Is Nothing) OrElse (Not ConnectionManager.GetConnectorContainer(point2.EditedConnectionPoint.AssociatedDesigner) Is Nothing))) Then
                point2.Location = point
                Me.activeEditPoint = point2
            End If
            Me.Invalidate
            Return (Not Me.activeEditPoint Is Nothing)
        End Function

        Public Sub OnContinueEditing(ByVal point As Point)
            If (Not Me.activeEditPoint Is Nothing) Then
                Me.Invalidate
                Me.UpdateEditPoints(point)
                Me.Invalidate
            End If
        End Sub

        Public Sub OnEndEditing(ByVal point As Point, ByVal commitChanges As Boolean)
            If (Not Me.activeEditPoint Is Nothing) Then
                Me.Invalidate
                If commitChanges Then
                    Me.UpdateEditPoints(point)
                    Dim activeEditPoint As EditPoint = Me.activeEditPoint
                    Me.activeEditPoint = Nothing
                    Me.UpdateEditPoints(point)
                    Dim flag As Boolean = False
                    If (activeEditPoint.Type = EditPointTypes.ConnectionEditPoint) Then
                        Dim service As ConnectionManager = [TryCast](Me.GetService(GetType(ConnectionManager)),ConnectionManager)
                        Dim connectorContainer As FreeformActivityDesigner = ConnectionManager.GetConnectorContainer(activeEditPoint.EditedConnectionPoint.AssociatedDesigner)
                        If (((Not service Is Nothing) AndAlso (Not service.SnappedConnectionPoint Is Nothing)) AndAlso (Not connectorContainer Is Nothing)) Then
                            Dim source As ConnectionPoint = Me.editedConnector.Source
                            Dim target As ConnectionPoint = Me.editedConnector.Target
                            If target.Equals(activeEditPoint.EditedConnectionPoint) Then
                                target = service.SnappedConnectionPoint
                            ElseIf source.Equals(activeEditPoint.EditedConnectionPoint) Then
                                source = service.SnappedConnectionPoint
                            End If
                            If ((connectorContainer Is ConnectionManager.GetConnectorContainer(target.AssociatedDesigner)) AndAlso connectorContainer.CanConnectContainedDesigners(source, target)) Then
                                Me.editedConnector.Source = source
                                Me.editedConnector.Target = target
                                If (Me.editedConnector.ParentDesigner Is Nothing) Then
                                    Me.editedConnector = connectorContainer.AddConnector(source, target)
                                    Dim loader As WorkflowDesignerLoader = [TryCast](Me.GetService(GetType(WorkflowDesignerLoader)),WorkflowDesignerLoader)
                                    If (Not loader Is Nothing) Then
                                        loader.SetModified(True)
                                    End If
                                End If
                                connectorContainer.OnContainedDesignersConnected(source, target)
                            End If
                            flag = True
                        End If
                    Else
                        flag = True
                    End If
                    If flag Then
                        Me.editedConnector.SetConnectorSegments(Me.GetPointsFromEditPoints(Me.editPoints))
                        If (Not Me.editedConnector.ParentDesigner Is Nothing) Then
                            Me.editedConnector.ParentDesigner.OnConnectorChanged(New ConnectorEventArgs(Me.editedConnector))
                            Dim loader2 As WorkflowDesignerLoader = [TryCast](Me.GetService(GetType(WorkflowDesignerLoader)),WorkflowDesignerLoader)
                            If (Not loader2 Is Nothing) Then
                                loader2.SetModified(True)
                            End If
                        End If
                    End If
                    Me.PerformLayout
                End If
                Me.Invalidate
            End If
        End Sub

        Public Sub OnPaint(ByVal e As ActivityDesignerPaintEventArgs, ByVal drawSelected As Boolean, ByVal drawPrimarySelection As Boolean)
            Dim list As New List([Of] Point)
            Dim list2 As New List([Of] Point)
            Dim i As Integer
            For i = 0 To Me.editPoints.Count - 1
                Dim point As EditPoint = Me.editPoints.Item(i)
                If ((point.Type = EditPointTypes.ConnectionEditPoint) OrElse (point.Type = EditPointTypes.MultiSegmentEditPoint)) Then
                    list.Add(point.Location)
                Else
                    list2.Add(point.Location)
                End If
            Next i
            If drawSelected Then
                Me.editedConnector.OnPaintSelected(e, drawPrimarySelection, list2.ToArray)
            End If
            If (Not Me.activeEditPoint Is Nothing) Then
                Me.editedConnector.OnPaintEdited(e, list.ToArray, list2.ToArray)
            End If
        End Sub

        Private Sub PerformLayout()
            Dim service As WorkflowView = [TryCast](Me.GetService(GetType(WorkflowView)),WorkflowView)
            If (Not service Is Nothing) Then
                service.PerformLayout(False)
            End If
        End Sub

        Private Sub RemoveCoincidingEditPoints()
            If (((Me.editPoints.Count >= 2) AndAlso (Me.editPoints.Item(0).Type = EditPointTypes.ConnectionEditPoint)) AndAlso ((Me.editPoints.Item((Me.editPoints.Count - 1)).Type = EditPointTypes.ConnectionEditPoint) AndAlso ((Me.activeEditPoint Is Nothing) OrElse (Me.activeEditPoint.Type <> EditPointTypes.ConnectionEditPoint)))) Then
                Me.RemoveEditPoints(EditPointTypes.MidSegmentEditPoint)
                Dim list As New List([Of] EditPoint)
                Dim i As Integer
                For i = 0 To Me.editPoints.Count - 1
                    If ((((Me.editPoints.Item(i).Type <> EditPointTypes.MultiSegmentEditPoint) OrElse (Me.editPoints.Item(i) Is Me.activeEditPoint)) OrElse ((i > 0) AndAlso (Me.editPoints.Item((i - 1)).Type = EditPointTypes.MidSegmentEditPoint))) OrElse ((i < (Me.editPoints.Count - 1)) AndAlso (Me.editPoints.Item((i + 1)).Type = EditPointTypes.MidSegmentEditPoint))) Then
                        list.Add(Me.editPoints.Item(i))
                    End If
                Next i
                Dim j As Integer
                For j = 1 To (Me.editPoints.Count - 1) - 1
                    Dim point As EditPoint = Me.editPoints.Item((j - 1))
                    Dim item As EditPoint = Me.editPoints.Item(j)
                    Dim point3 As EditPoint = Me.editPoints.Item((j + 1))
                    If Not list.Contains(item) Then
                        Dim segments As Point() = New Point() { point.Location, item.Location }
                        Dim num3 As Double = DesignerGeometryHelper.DistanceOfLineSegments(segments)
                        If (((num3 < item.Bounds.Width) OrElse (num3 < item.Bounds.Height)) AndAlso (point3.Type = EditPointTypes.MultiSegmentEditPoint)) Then
                            Dim num4 As Single = DesignerGeometryHelper.SlopeOfLineSegment(item.Location, point3.Location)
                            point3.Location = If((num4 < 1!), New Point(point3.Location.X, point.Location.Y), New Point(point.Location.X, point3.Location.Y))
                            Me.editPoints.Remove(item)
                            j -= 1
                        Else
                            Dim pointArray2 As Point() = New Point() { item.Location, point3.Location }
                            num3 = DesignerGeometryHelper.DistanceOfLineSegments(pointArray2)
                            If (((num3 < item.Bounds.Width) OrElse (num3 < item.Bounds.Height)) AndAlso (point.Type = EditPointTypes.MultiSegmentEditPoint)) Then
                                Dim num5 As Single = DesignerGeometryHelper.SlopeOfLineSegment(point.Location, item.Location)
                                point.Location = If((num5 < 1!), New Point(point.Location.X, point3.Location.Y), New Point(point3.Location.X, point.Location.Y))
                                Me.editPoints.Remove(item)
                                j -= 1
                            End If
                        End If
                    End If
                Next j
                Dim k As Integer
                For k = 1 To (Me.editPoints.Count - 1) - 1
                    Dim point4 As EditPoint = Me.editPoints.Item(k)
                    Dim point5 As EditPoint = Me.editPoints.Item((k - 1))
                    Dim point6 As EditPoint = Me.editPoints.Item((k + 1))
                    If Not list.Contains(point4) Then
                        Dim num7 As Single = DesignerGeometryHelper.SlopeOfLineSegment(point5.Location, point4.Location)
                        Dim num8 As Single = DesignerGeometryHelper.SlopeOfLineSegment(point4.Location, point6.Location)
                        If (Math.Abs(num7) = Math.Abs(num8)) Then
                            Me.editPoints.Remove(point4)
                            k -= 1
                        End If
                    End If
                Next k
                Dim m As Integer
                For m = 0 To (Me.editPoints.Count - 1) - 1
                    Dim point7 As EditPoint = Me.editPoints.Item(m)
                    Dim point8 As EditPoint = Me.editPoints.Item((m + 1))
                    Dim num10 As Single = DesignerGeometryHelper.SlopeOfLineSegment(point7.Location, point8.Location)
                    If ((num10 <> 0!) AndAlso (num10 <> Single.MaxValue)) Then
                        Dim point9 As Point = If((num10 < 1!), New Point(point8.Location.X, point7.Location.Y), New Point(point7.Location.X, point8.Location.Y))
                        Me.editPoints.Insert((m + 1), New EditPoint(Me, EditPointTypes.MultiSegmentEditPoint, point9))
                    End If
                Next m
            End If
        End Sub

        Private Sub RemoveEditPoints(ByVal editPointType As EditPointTypes)
            Dim list As New List([Of] EditPoint)
            Dim i As Integer
            For i = 0 To Me.editPoints.Count - 1
                Dim item As EditPoint = Me.editPoints.Item(i)
                If (item.Type = editPointType) Then
                    list.Add(item)
                End If
            Next i
            Dim j As Integer
            For j = 0 To list.Count - 1
                Dim point2 As EditPoint = list.Item(j)
                If (Not point2 Is Me.activeEditPoint) Then
                    Me.editPoints.Remove(point2)
                End If
            Next j
        End Sub

        Private Sub UpdateEditPoints(ByVal newPoint As Point)
            If (((Me.editPoints.Count >= 2) AndAlso (Me.editPoints.Item(0).Type = EditPointTypes.ConnectionEditPoint)) AndAlso (Me.editPoints.Item((Me.editPoints.Count - 1)).Type = EditPointTypes.ConnectionEditPoint)) Then
                Me.RemoveEditPoints(EditPointTypes.MidSegmentEditPoint)
                If (Not Me.activeEditPoint Is Nothing) Then
                    Dim index As Integer = Me.editPoints.IndexOf(Me.activeEditPoint)
                    Dim point As EditPoint = If((index > 0), Me.editPoints.Item((index - 1)), Nothing)
                    Dim point2 As EditPoint = If((index < (Me.editPoints.Count - 1)), Me.editPoints.Item((index + 1)), Nothing)
                    If ((Not point Is Nothing) AndAlso (point.Type = EditPointTypes.ConnectionEditPoint)) Then
                        Dim orientation As Orientation = If((Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(point.Location, Me.activeEditPoint.Location)) < 1!), Orientation.Horizontal, Orientation.Vertical)
                        Dim num3 As Integer = (Convert.ToInt32(DesignerGeometryHelper.DistanceBetweenPoints(point.Location, If((Not point2 Is Nothing), point2.Location, Me.activeEditPoint.Location))) / 4)
                        If (orientation = Orientation.Horizontal) Then
                            num3 = (num3 * If((point.Location.X < Me.activeEditPoint.Location.X), 1, -1))
                        Else
                            num3 = (num3 * If((point.Location.Y < Me.activeEditPoint.Location.X), 1, -1))
                        End If
                        index = Me.editPoints.IndexOf(Me.activeEditPoint)
                        Dim point3 As Point = If((orientation = Orientation.Horizontal), New Point((point.Location.X + num3), point.Location.Y), New Point(point.Location.X, (point.Location.Y + num3)))
                        point = New EditPoint(Me, EditPointTypes.MultiSegmentEditPoint, point3)
                        Me.editPoints.InsertRange(index, New EditPoint() { New EditPoint(Me, EditPointTypes.MultiSegmentEditPoint, point3), point })
                    End If
                    If ((Not point2 Is Nothing) AndAlso (point2.Type = EditPointTypes.ConnectionEditPoint)) Then
                        Dim orientation2 As Orientation = If((Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(Me.activeEditPoint.Location, point2.Location)) < 1!), Orientation.Horizontal, Orientation.Vertical)
                        Dim num5 As Integer = (Convert.ToInt32(DesignerGeometryHelper.DistanceBetweenPoints(If((Not point Is Nothing), point.Location, Me.activeEditPoint.Location), point2.Location)) / 4)
                        If (orientation2 = Orientation.Horizontal) Then
                            num5 = (num5 * If((Me.activeEditPoint.Location.X < point2.Location.X), -1, 1))
                        Else
                            num5 = (num5 * If((Me.activeEditPoint.Location.Y < point2.Location.Y), -1, 1))
                        End If
                        index = Me.editPoints.IndexOf(Me.activeEditPoint)
                        Dim point4 As Point = If((orientation2 = Orientation.Horizontal), New Point((point2.Location.X + num5), point2.Location.Y), New Point(point2.Location.X, (point2.Location.Y + num5)))
                        point2 = New EditPoint(Me, EditPointTypes.MultiSegmentEditPoint, point4)
                        Me.editPoints.InsertRange((index + 1), New EditPoint() { point2, New EditPoint(Me, EditPointTypes.MultiSegmentEditPoint, point4) })
                    End If
                    If (Me.activeEditPoint.Type = EditPointTypes.ConnectionEditPoint) Then
                        Me.activeEditPoint.Location = newPoint
                        Me.RemoveEditPoints(EditPointTypes.MultiSegmentEditPoint)
                        Dim source As Object = Nothing
                        Dim target As Object = Nothing
                        If Me.activeEditPoint.EditedConnectionPoint.Equals(Me.Target) Then
                            target = newPoint
                            source = Me.Source
                        Else
                            source = newPoint
                            target = Me.Target
                        End If
                        Dim num6 As Integer = If((Me.editPoints.Count = 2), 1, 0)
                        Dim list As New List([Of] EditPoint)
                        Dim pointArray As Point() = ActivityDesignerConnectorRouter.Route(Me.serviceProvider, source, target, Me.editedConnector.ExcludedRoutingRectangles)
                        Dim i As Integer
                        For i = num6 To (pointArray.Length - num6) - 1
                            list.Add(New EditPoint(Me, EditPointTypes.MultiSegmentEditPoint, pointArray(i)))
                        Next i
                        Me.editPoints.InsertRange(1, list.ToArray)
                    ElseIf (Me.activeEditPoint.Type = EditPointTypes.MultiSegmentEditPoint) Then
                        If (((Not point Is Nothing) AndAlso (point.Type <> EditPointTypes.ConnectionEditPoint)) AndAlso ((Not point2 Is Nothing) AndAlso (point2.Type <> EditPointTypes.ConnectionEditPoint))) Then
                            Dim orientation3 As Orientation = If((Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(point.Location, Me.activeEditPoint.Location)) < 1!), Orientation.Horizontal, Orientation.Vertical)
                            point.Location = If((orientation3 = Orientation.Horizontal), New Point(point.Location.X, newPoint.Y), New Point(newPoint.X, point.Location.Y))
                            orientation3 = If((Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(Me.activeEditPoint.Location, point2.Location)) < 1!), Orientation.Horizontal, Orientation.Vertical)
                            point2.Location = If((orientation3 = Orientation.Horizontal), New Point(point2.Location.X, newPoint.Y), New Point(newPoint.X, point2.Location.Y))
                            Me.activeEditPoint.Location = newPoint
                        End If
                    ElseIf ((((Me.activeEditPoint.Type = EditPointTypes.MidSegmentEditPoint) AndAlso (Not point Is Nothing)) AndAlso ((point.Type <> EditPointTypes.ConnectionEditPoint) AndAlso (Not point2 Is Nothing))) AndAlso (point2.Type <> EditPointTypes.ConnectionEditPoint)) Then
                        If (If((Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(point.Location, point2.Location)) < 1!), 0, 1) = 0) Then
                            point.Location = New Point(point.Location.X, newPoint.Y)
                            point2.Location = New Point(point2.Location.X, newPoint.Y)
                            Me.activeEditPoint.Location = New Point(Me.activeEditPoint.Location.X, newPoint.Y)
                        Else
                            point.Location = New Point(newPoint.X, point.Location.Y)
                            point2.Location = New Point(newPoint.X, point2.Location.Y)
                            Me.activeEditPoint.Location = New Point(newPoint.X, Me.activeEditPoint.Location.Y)
                        End If
                    End If
                End If
                Me.RemoveCoincidingEditPoints
                Me.AddEditPoints(EditPointTypes.MidSegmentEditPoint)
                Me.ValidateEditPoints
            End If
        End Sub

        Private Function ValidateEditPoints() As Boolean
            If (Me.editPoints.Count < 2) Then
                Return False
            End If
            Dim editedConnectionPoint As ConnectionPoint = Me.editPoints.Item(0).EditedConnectionPoint
            If ((editedConnectionPoint Is Nothing) OrElse Not editedConnectionPoint.Equals(Me.Source)) Then
                Return False
            End If
            Dim point2 As ConnectionPoint = Me.editPoints.Item((Me.editPoints.Count - 1)).EditedConnectionPoint
            If ((point2 Is Nothing) OrElse Not point2.Equals(Me.Target)) Then
                Return False
            End If
            Dim i As Integer
            For i = 0 To (Me.editPoints.Count - 1) - 1
                If ((Me.editPoints.Item(i).Type = EditPointTypes.MidSegmentEditPoint) AndAlso (Me.editPoints.Item((i + 1)).Type = EditPointTypes.MidSegmentEditPoint)) Then
                    Return False
                End If
            Next i
            Return True
        End Function


        ' Properties
        Public ReadOnly Property EditedConectionPoint As ConnectionPoint
            Get
                If (Not Me.activeEditPoint Is Nothing) Then
                    Return Me.activeEditPoint.EditedConnectionPoint
                End If
                Return Nothing
            End Get
        End Property

        Public ReadOnly Property EditedConnector As Connector
            Get
                Return Me.editedConnector
            End Get
        End Property

        Private ReadOnly Property Source As ConnectionPoint
            Get
                Return Me.editedConnector.Source
            End Get
        End Property

        Private ReadOnly Property Target As ConnectionPoint
            Get
                Return Me.editedConnector.Target
            End Get
        End Property


        ' Fields
        Private activeEditPoint As EditPoint
        Private editedConnector As Connector
        Private editPoints As List([Of] EditPoint) = New List([Of] EditPoint)
        Private serviceProvider As IServiceProvider

        ' Nested Types
        Private NotInheritable Class EditPoint
            ' Methods
            Public Sub New(ByVal owner As ConnectorEditor, ByVal connectionPoint As ConnectionPoint)
                Me.owner = owner
                Me.editPointType = EditPointTypes.ConnectionEditPoint
                Me.connectionPoint = connectionPoint
                Me.point = connectionPoint.Location
            End Sub

            Public Sub New(ByVal owner As ConnectorEditor, ByVal editPointType As EditPointTypes, ByVal point As Point)
                Me.owner = owner
                Me.editPointType = editPointType
                Me.point = point
            End Sub


            ' Properties
            Public ReadOnly Property Bounds As Rectangle
                Get
                    Dim size As Size = Me.owner.Source.Bounds.Size
                    Return New Rectangle((Me.point.X - (size.Width / 2)), (Me.point.Y - (size.Height / 2)), size.Width, size.Height)
                End Get
            End Property

            Public ReadOnly Property EditedConnectionPoint As ConnectionPoint
                Get
                    Return Me.connectionPoint
                End Get
            End Property

            Public Property Location As Point
                Get
                    Return Me.point
                End Get
                Set(ByVal value As Point)
                    Me.point = value
                End Set
            End Property

            Public ReadOnly Property Type As EditPointTypes
                Get
                    Return Me.editPointType
                End Get
            End Property


            ' Fields
            Private connectionPoint As ConnectionPoint
            Private editPointType As EditPointTypes
            Private owner As ConnectorEditor
            Private point As Point

            ' Nested Types
            Public Enum EditPointTypes
                ' Fields
                ConnectionEditPoint = 1
                MidSegmentEditPoint = 3
                MultiSegmentEditPoint = 2
            End Enum
        End Class
    End Class
End Namespace

